<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Transaksi - Faktur Penjualan</title>
<link href="<?php echo base_url(); ?>assets/css/style-trx.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" href="<?php echo base_url()?>assets/jqueryui/themes/jquery.ui.all.css">
</head>
<body style="background:#CCC; font-size:70%;">
<center>
<div class="kanvas">
<div class="trx-title"><a href="<?php echo base_url()?>index.php/home">Home</a> &raquo; Transaksi &raquo; Sales Order</div>
<div class="trx">
<?php
//echo $ses_saleid;
$attributes = array('name' => 'f_so','onSubmit' => 'return validate(this)','id' => 'f_submit');
echo form_open('transaksi/sales_order/simpan',$attributes);
?>
<table width="100%" class="trx-form">
<tr>
	<td width="9%" height="20"><strong>Pilih Pelanggan</strong></td>
    <td width="16%">
    	<input type="hidden" class="input" id="kdcus1" name="pelanggan1" value="<?php if(!empty($ses_saleid)) echo $row->pelanggan1;?>"/>
    	<input type="text" class="input" id="nama1" placeholder="Kepada" value="<?php if(!empty($ses_saleid)) echo $row->kepada;?>"/>
    </td>
    <td width="1%">
    </td>
    <td width="5%"><strong>Untuk</strong></td>
    <td width="17%">
    	<input type="hidden" class="input" id="kdcus2" name="pelanggan2" value="<?php if(!empty($ses_saleid)) echo $row->pelanggan2;?>"/>
    	<input type="text" class="input" id="nama2" placeholder="Untuk" value="<?php if(!empty($ses_saleid)) echo $row->untuk;?>"/>
    </td>
    <td width="2%">
    </td>
    <td width="7%"><strong>Sales</strong></td>
    <td width="17%">
    	<input type="hidden" name="sales" class="input" id="sales_id" value="<?php if(!empty($ses_saleid)) echo $row->sales;?>"/>
    	<input type="text" class="input" id="nama_sales" placeholder="Nama Sales" value="<?php if(!empty($ses_saleid)) echo $row->nama_sales;?>"/>
    </td>
    <td width="3%">
    </td>
    <td width="6%"><strong>Tender</strong></td>
    <td width="17%">
    	<select name="tender">
      		<option value="1" <?php if(!empty($ses_saleid)){ if($row->tender == '1') echo "selected"; }?>>Tender </option>
      		<option value="2" <?php if(!empty($ses_saleid)){ if($row->tender == '2') echo "selected"; }?>>Non Tender </option>
    	</select>
    </td>
</tr>
<tr>
	<td width="9%" height="20"></td>
    <td width="16%">
    	<input type="text" placeholder="Alamat.." class="input" name="alamat1" id="alamat1" value="<?php if(!empty($ses_saleid)) echo $row->alamat1;?>"/>
    </td>
    <td width="1%">
    </td>
    <td width="5%"></td>
    <td width="17%">
    	<input type="text" placeholder="Alamat.." class="input" name="alamat2" id="alamat2" value="<?php if(!empty($ses_saleid)) echo $row->alamat2;?>"/>
    </td>
    <td width="2%">
    </td>
    <td width="7%"></td>
    <td width="17%">
    	<input type="text" placeholder="Alamat.." class="input" name="alamat3" id="alamat3" value="<?php if(!empty($ses_saleid)) echo $row->alamat3;?>"/>
    </td>
    <td width="3%">
    </td>
    <td width="6%"><strong>Jenis</strong></td>
    <td width="17%">
      <input type="radio" name="tipetrn" value="1" <?php if(!empty($ses_saleid)){ if($row->jenis == '1') echo "CHECKED"; }?>/>
      Ins
      <input type="radio" name="tipetrn" value="2" <?php if(!empty($ses_saleid)){ if($row->jenis == '2') echo "CHECKED"; }?>/>
      Reg </td>
    </tr>
<tr>
	<td width="9%" height="20"></td>
    <td width="16%">
    	<input type="text" placeholder="Kota.." class="input" name="kota1" id="kota1" value="<?php if(!empty($ses_saleid)) echo $row->kota1;?>"/>
    </td>
    <td width="1%">
    </td>
    <td width="5%"></td>
    <td width="17%">
    	<input type="text" placeholder="Kota.." class="input" name="kota2" id="kota2" value="<?php if(!empty($ses_saleid)) echo $row->kota2;?>"/>
    </td>
    <td width="2%">
    </td>
    <td width="7%"></td>
    <td width="17%">
    	<input type="text" placeholder="Kota.." class="input" name="kota3" id="kota3" value="<?php if(!empty($ses_saleid)) echo $row->kota3;?>"/>
    </td>
    <td width="3%">
    </td>
    <td width="6%"><strong>Tanggal</strong></td>
    <td width="17%"><input type="text" name="tgl" class="input center" value="<?php echo $tanggal;?>"/></td>
    </tr>
<tr>
	<td width="9%" height="20"></td>
    <td width="16%">
    	<input type="text" placeholder="Tlp.." class="input" name="tlp1" id="tlp1" value="<?php if(!empty($ses_saleid)) echo $row->tlp1;?>"/>
    </td>
    <td width="1%">
    </td>
    <td width="5%"></td>
    <td width="17%">
    	<input type="text" placeholder="Tlp.." class="input" name="tlp2" id="tlp2" value="<?php if(!empty($ses_saleid)) echo $row->tlp2;?>"/>
    </td>
    <td width="2%">
    </td>
    <td width="7%"></td>
    <td width="17%">
    	<input type="text" placeholder="Tlp.." class="input" name="tlp3" id="tlp3" value="<?php if(!empty($ses_saleid)) echo $row->tlp3;?>"/>
    </td>
    <td width="3%">
    </td>
    <td width="6%">&nbsp;</td>
    <td width="17%">&nbsp;</td>
    </tr>
<tr>
	<td width="9%" height="20"><strong>NPWP</strong></td>
    <td width="16%">
    	<input type="text" class="input" name="npwp" value="<?php if(!empty($ses_saleid)) echo $row->npwp1;?>"/>
    </td>
    <td width="1%">
    </td>
    <td width="5%">&nbsp;</td>
    <td width="17%">
    	<input type="text" class="input" value="<?php if(!empty($ses_saleid)) echo $row->npwp2;?>"/>
    </td>
    <td width="2%">
    </td>
    <td width="7%">&nbsp;</td>
    <td width="17%">
    	<input type="text" class="input" value="<?php if(!empty($ses_saleid)) echo $row->npwp2;?>"/>
    </td>
    <td width="3%">
    </td>
    <td width="6%">&nbsp;</td>
    <td width="17%">&nbsp;</td>
    </tr>
</table>
<hr />
<!--
<table width="100%" cellspacing="2" border="0">
  <tr>
	<td colspan="2"><b>Kode</b></td>
	<td width="15%">
    	
    </td>
	<td width="23%">&nbsp;</td>
    <td width="13%">&nbsp;</td>
    <td width="42%">
    </td>
</tr>
<tr>
	<td colspan="2"><b>Pilih Harga</b></td>
	<td>&nbsp;</td>
	<td colspan="4" align="left">&nbsp;</td>
</tr>
<tr>
	<td width="4%"><b>Harga</b></td>
	<td width="3%"><b>Rp</b></td>
    <td>&nbsp;</td>
</tr>
<tr>
	<td colspan="2"><b>Qty</b></td>
	<td>&nbsp;</td>
	<td colspan="4" align="left">&nbsp;</td>
</tr>
<tr>
	<td><b>Disc</b></td>
	<td width="3%"><b>%</b></td>
	<td>&nbsp;</td>
	<td colspan="4" align="left">&nbsp;</td>
</tr>
<tr>
	<td width="4%" align="right"><div align="left"><b>Total</b>&nbsp;</div></td>
	<td width="3%"><b>Rp</b></td>
    <td width="15%">&nbsp;</td>
</tr>-->
<tr>
	<td colspan="6">
    	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="trx-table">
        	<tr height="25">
            	<td width="12%" align="center"><strong>Kode</strong></td>
            	<td width="20%" align="center"><strong>Nama</strong></td>
            	<td width="10%" align="center"><strong>Satuan</strong></td>
            	<td width="10%" align="center"><strong>Pilih</strong></td>
            	<td width="12%" align="center"><strong>Harga</strong></td>
            	<td width="12%" align="center"><strong>Qty</strong></td>
            	<td width="12%" align="center"><strong>Diskon</strong></td>
            	<td width="12%" align="center"><strong>Total</strong></td>
            </tr>
        </table>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="trx-table-detail">
            <tr height="25">
            	<td width="12%" >
                	<input type="text" class="input center" name="prokode" id="prokode" placeholder="kode" 
                    value="<?php if(!empty($res_saleid)) echo $res->prokode;?>"/>
                </td>
            	<td width="20%" align="center">
                	<input type="text" class="input" name="nama" id="nama" placeholder="Nama Barang" 
                    value="<?php if(!empty($res_saleid)) echo $res->nama;?>"/>
                </td>
            	<td width="10%" align="center">
                	<input type="text" class="input" readonly="readonly" id="satuan" 
                    name="satuan" placeholder="Satuan.." value="<?php if(!empty($res_saleid)) echo $res->satuan;?>"/>
        		</td>
            	<td width="10%" align="center">
                	<select name="phg" id="phg" class="input">
                      <option value="1" <?php if(!empty($res_saleid)){ if($res->phg == '1') echo "SELECTED"; }?>>Harga 1 </option>
                      <option value="2" <?php if(!empty($res_saleid)){ if($res->phg == '2') echo "SELECTED"; }?>>Harga 2 </option>
                      <option value="3" <?php if(!empty($res_saleid)){ if($res->phg == '3') echo "SELECTED"; }?>>Harga 3 </option>
                      <option value="4" <?php if(!empty($res_saleid)){ if($res->phg == '4') echo "SELECTED"; }?>>Harga 4 </option>
                      <option value="5" <?php if(!empty($res_saleid)){ if($res->phg == '5') echo "SELECTED"; }?>>Harga 5 </option>
          	  		</select>
                </td>
            	<td width="12%">
                	<input type="text" class="input right" name="harga" id="harga" 
       				placeholder="Harga" onkeyup="format_harga()" value="<?php if(!empty($res_saleid)) echo $res->price;?>"/>
                </td>
            	<td width="12%" align="center">
                	<input type="text" class="input center" name="qty" id="qty" 
                    placeholder="Jumlah" onkeyup="format_qty()" autocomplete="off" value="<?php if(!empty($res_saleid)) echo $res->qty;?>"/>
                </td>
            	<td width="12%" align="center">
                	<input type="text" size="10" class="input center" name="disc" id="disc" 
                    placeholder="Diskon.." onkeyup="format_disc()" autocomplete="off" value="<?php if(!empty($res_saleid)) echo $res->diskon;?>"/>
                </td>
            	<td width="12%" align="center">
                	<input type="text" class="input right" name="total" id="total" 
        			placeholder="Total" readonly="readonly" value="<?php if(!empty($res_saleid)) echo $res->total;?>"/>
                </td>
            </tr>
        </table>  
    </td>
</tr>
<tr>
	<td height="40" colspan="6">&nbsp;&nbsp;</td>
</tr>
<tr>
	<td colspan="6" align="right">
    	<table border="0">
        	<tr>
            	<td>
            	  <input type="submit" name="<?php echo $submit; ?>" value="Simpan" class="tombol" />
                  <input type="hidden" name="no" value="<?php if(!empty($res_saleid)) echo $res->no;?>"/>
                  <input type="hidden" name="saleid" value="<?php if(!empty($ses_saleid)) echo $ses_saleid;?>"/>
            	  <input type="submit" name="batal" value="Batal" class="tombol" />
               	  <input type="submit" name="clear" value="Selesai" class="tombol" />
               </td>
            </tr>
        </table>
    </td>
</tr>
</table>
<hr />
<?php
echo form_close();
?>
<table width="100%" cellspacing="0" border="0" class="trx-table">
<tr height="25">
    <td width="5%"></td>
	<td width="12%" align="center" valign="middle"><strong>Kode</strong></td>
	<td width="30%" align="center" valign="middle"><strong>Nama</strong></td>
	<td width="12%" align="center" valign="middle"><strong>Satuan</strong></td>
	<td width="12%" align="center" valign="middle"><strong>Harga</strong></td>
	<td width="8%" align="center" valign="middle"><strong>Qty</strong></td>
	<td width="8%" align="center" valign="middle"><strong>Diskon</strong></td>
	<td width="13%" align="center" valign="middle"><strong>Total</strong></td>
</tr>
</table>
<div style="width:100%; height:150px; overflow:auto; border-bottom:1px solid #000;" />
<?php
if(!empty($tampil)){
?>
<table width="100%" cellspacing="0" border="0" class="trx-table-detail">
<?php
foreach($tampil as $val){
?>
  <tr height="28">
	<td width="5%" align="center">
    	<a href="<?php echo site_url()?>/transaksi/sales_order/tampil/<?php echo $val->saleid;?>">
    	<img src="<?php echo base_url();?>assets/img/edit.png" width="40%"/>
        </a>
    	<a href="<?php echo site_url()?>/transaksi/sales_order/hapus/<?php echo $val->saleid;?>">
    	<img src="<?php echo base_url();?>assets/img/delete	.png" width="40%"/>
        </a>
    </td>
	<td width="12%" align="center"><?php echo $val->prokode;?></td>
	<td width="30%" align="left">&nbsp;<?php echo $val->nama;?></td>
	<td width="12%" align="center">&nbsp;<?php echo $val->satuan;?></td>
	<td width="12%" align="right">&nbsp;<?php echo number_format($val->price,0,'','.');?></td>
	<td width="8%" align="center"><?php echo $val->qty;?></td>
	<td width="8%" align="center"><?php echo $val->diskon;?></td>
	<td width="13%" align="right">&nbsp;<?php echo number_format($val->total,0,'','.');?></td>
</tr>
<?php
	}
?>
</table>
<?php
}
?>
</div>
<div align="left">
  <table class="trx-form">
    <tr>
	  	<td><strong>Total Order</strong></td>
		<td><input type="text" class="input right" value="<?php if(!empty($ses_saleid)) echo number_format($row->total_order,0,'','.');?>"/></td>
	  	<td><strong>PPn</strong></td>
		<td><input type="text" class="input right" value="<?php if(!empty($ses_saleid)) echo number_format($row->ppn,0,'','.');?>"/></td>
    </tr>
	<tr>
	  	<td><strong>Diskon</strong></td>
		<td><input type="text" class="input right" value="<?php if(!empty($ses_saleid)) echo number_format($row->diskon,0,'','.');?>"/></td>
	  	<td><strong>Netto PPn</strong></td>
		<td><input type="text" class="input right"  value="<?php if(!empty($ses_saleid)) echo number_format($row->nettoppn,0,'','.');?>"/></td>
    </tr>
	<tr>
	  	<td><strong>Netto</strong></td>
		<td><input type="text" class="input right" value="<?php if(!empty($ses_saleid)) echo number_format($row->netto,0,'','.');?>"/></td>
    </tr>
</table>
</div>
</div>
</center>
</body>
</html>
	<script src="<?php echo base_url()?>assets/jqueryui/jquery-1.9.1.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.core.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.widget.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.position.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.menu.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.autocomplete.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.datepicker.js"></script>
   	<script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.tooltip.js"></script>
    <script>
	$(function() {
		$( document ).tooltip({
			position: {
				my: "center bottom-20",
				at: "center top",
				using: function( position, feedback ) {
					$( this ).css( position );
					$( "<div>" )
						.addClass( "arrow" )
						.addClass( feedback.vertical )
						.addClass( feedback.horizontal )
						.appendTo( this );
				}
			}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama").autocomplete({
		source: site+"/transaksi/search/barang",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#prokode').val(hasil[0]);
			$('#nama').val(hasil[1]);
			$('#qty').val('1').focus();
			$('#harga').val(hasil[2]);
			$('#satuan').val(hasil[3]);
			$('#total').val(hasil[2]*1);
			return false;
		}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama1").autocomplete({
		source: site+"/transaksi/search/pelanggan",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#kdcus1').val(hasil[0]);
			$('#nama1').val(hasil[1]);
			$('#alamat1').val(hasil[2]);
			$('#kota1').val(hasil[3]);
			$('#tlp1').val(hasil[4]);
			return false;
		}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama2").autocomplete({
		source: site+"/transaksi/search/pelanggan",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#kdcus2').val(hasil[0]);
			$('#nama2').val(hasil[1]);
			$('#alamat2').val(hasil[2]);
			$('#kota2').val(hasil[3]);
			$('#tlp2').val(hasil[4]);
			return false;
		}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama_sales").autocomplete({
		source: site+"/transaksi/search/sales",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#sales_id').val(hasil[0]);
			$('#nama_sales').val(hasil[1]);
			$('#alamat3').val(hasil[2]);
			$('#kota3').val(hasil[3]);
			$('#tlp3').val(hasil[4]);
			return false;
		}
		});
	});
		
function formatNumber (obj, decimal) {
	anynum=eval(obj.value);
	divider =10;
	switch(decimal){
		case 0:
			divider =1;
			break;
		case 1:
			divider =10;
			break;
		case 2:
			divider =100;
			break;
		default:  	 //for 3 decimal places
			divider =1000;
	}
	workNum=Math.abs((Math.round(anynum*divider)/divider));
	workStr=""+workNum
	if (workStr.indexOf(".")==-1){workStr+="."}
	dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
	pStr=workStr.substr(workStr.indexOf("."))
	while (pStr.length-1< decimal){pStr+="0"}
	if(pStr =='.') pStr ='';
	//--- Adds a comma in the thousands place.    
	if (dNum>=1000) {
		dLen=dStr.length
		dStr=parseInt(""+(dNum/1000))+"."+dStr.substring(dLen-3,dLen)
	}
	//-- Adds a comma in the millions place.
	if (dNum>=1000000) {
		dLen=dStr.length
		dStr=parseInt(""+(dNum/1000000))+"."+dStr.substring(dLen-7,dLen)
	}
	retval = dStr + pStr
	//-- Put numbers in parentheses if negative.
	if (anynum<0) {retval="("+retval+")";}
	//retval =  "$"+retval
	obj.value = retval;
}

function format_harga() {
  var harga = document.f_so.harga.value;
  harga = harga.replace(/[^0-9.]/g,"");
  harga = harga.replace(".","");
  harga = harga.replace(".","");
  if(harga.length == 0) harga = "0";	

  var qty = document.f_so.qty.value;
  qty = qty.replace(/[^0-9.]/g,"");
  qty = qty.replace(".","");
  qty = qty.replace(".","");
  if(qty.length == 0) qty = "0";	
  
  var total = harga * qty;

  if(qty.length > 0) {
    if(!isNaN(qty)) {
      document.f_so.harga.value = harga;
      document.f_so.qty.value = qty;
      document.f_so.total.value = total;
      formatNumber(document.f_so.harga,0);
      formatNumber(document.f_so.qty,0);
      formatNumber(document.f_so.total,0);
     }	
  } else { document.f_so.qty.value = "0"; }			

}

function format_qty() {
  var harga = document.f_so.harga.value;
  if(harga.length == 0) harga = "0";	

  var qty = document.f_so.qty.value;
  qty = qty.replace(/[^0-9.]/g,"");
  qty = qty.replace(".","");
  qty = qty.replace(".","");
  if(qty.length == 0) qty = "0";	
  
  var total = parseFloat(harga) * qty;

  if(qty.length > 0) {
    if(!isNaN(qty)) {
      document.f_so.qty.value = qty;
      document.f_so.total.value = total;
      formatNumber(document.f_so.qty,0);
      formatNumber(document.f_so.total,1);
     }	
  } else { document.f_so.qty.value = "0"; }			

}

function format_disc() {
  var harga = document.f_so.harga.value;
  harga = harga.replace(/[^0-9.]/g,"");
  harga = harga.replace(".","");
  harga = harga.replace(".","");
  if(harga.length == 0) harga = "0";	

  var qty = document.f_so.qty.value;
  qty = qty.replace(/[^0-9.]/g,"");
  qty = qty.replace(".","");
  qty = qty.replace(".","");
  if(qty.length == 0) qty = "0";	

  var disc = document.f_so.disc.value;
  if(disc.length == 0) disc = "0";
  
  var total = harga * qty * ( 100 - disc)/100;

  if(qty.length > 0) {
    if(!isNaN(qty)) {
      document.f_so.qty.value   = qty;
      document.f_so.total.value = total;
      document.f_so.disc.value  = disc;
      formatNumber(document.f_so.qty,0);
      formatNumber(document.f_so.total,0);
     }	
  } else { document.f_so.qty.value = "0"; }			

}

    function hapus(brg){
        var agree = confirm("Anda Yakin Ingin Menghapus " +  brg  + "?");
        if(agree){
            return true;
        }else{
            return false;
        }
    }

$(function () {
  $("#phg").change(function () {
	//var prokode = document.f_so.prokode.value;
    //$("#harga").load('<?php echo site_url()?>/transaksi/sales_order/pilih_harga?phg=' + $(this).val()+ '&prokode='+prokode);
    $.get('<?php echo site_url()?>/transaksi/sales_order/pilih_harga',{ 
	        phg:$(this).val(),
	        prokode: document.f_so.prokode.value
        } ,function(data) {
            document.f_so.harga.value = data;
            var qty   = document.f_so.qty.value;
            var harga = document.f_so.harga.value;
			var disc = document.f_so.disc.value;            
            
            var total = harga * qty * ( 100 - disc)/100;
            
            document.f_so.total.value = total;
    });
  });
});
</script>    
